<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>带索引检查计算数组的交集</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.array-flip.html">array_flip</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.array-intersect-key.html">array_intersect_key</a></div>
 <div class="up"><a href="ref.array.html">数组 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.array-intersect-assoc" class="refentry">
 <div class="refnamediv">   <h1 class="refname">array_intersect_assoc</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.3.0, PHP 5)</p><p class="refpurpose"><span class="refname">array_intersect_assoc</span> &mdash; <span class="dc-title">带索引检查计算数组的交集</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.array-intersect-assoc-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">array</span> <span class="methodname"><strong>array_intersect_assoc</strong></span>
    ( <span class="methodparam"><span class="type">array</span> <code class="parameter">$array1</code></span>
   , <span class="methodparam"><span class="type">array</span> <code class="parameter">$array2</code></span>
   [, <span class="methodparam"><span class="type">array</span> <code class="parameter">$ ...</code></span>
  ] )</div>

  <p class="simpara">
   <span class="function"><strong>array_intersect_assoc()</strong></span> 返回一个数组，该数组包含了所有在
   <em><code class="parameter">array1</code></em> 中也同时出现在所有其它参数数组中的值。注意和
   <span class="function"><a href="function.array-intersect.html" class="function">array_intersect()</a></span> 不同的是键名也用于比较。
  </p>
  </div>

 
  <div class="refsect1 parameters" id="refsect1-function.array-intersect-assoc-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<em><code class="parameter">array1</code></em></dt>

     <dd>

      <p class="para">
       The array with master values to check.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">array2</code></em></dt>

     <dd>

      <p class="para">
       An array to compare values against.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">array</code></em></dt>

     <dd>

      <p class="para">
       要对比的数组变量的列表。
      </p>
     </dd>

    
   </dl>

  </p>
 </div>

 
   <div class="refsect1 returnvalues" id="refsect1-function.array-intersect-assoc-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
    返回一个数组，该数组包含了所有在
   <em><code class="parameter">array1</code></em> 中也同时出现在所有其它参数数组中的值。
  </p>
 </div>

 
 <div class="refsect1 examples" id="refsect1-function.array-intersect-assoc-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-4850">
    <p><strong>Example #1 <span class="function"><strong>array_intersect_assoc()</strong></span> 例子</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$array1&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #DD0000">"a"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">"green"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"b"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">"brown"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"c"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">"blue"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"red"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$array2&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #DD0000">"a"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">"green"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"b"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">"yellow"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"blue"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"red"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$result_array&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">array_intersect_assoc</span><span style="color: #007700">(</span><span style="color: #0000BB">$array1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$array2</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$result_array</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
Array
(
    [a] =&gt; green
)
</pre></div>
    </div>
   </div>
  </p>
  <p class="simpara">
   上面例子中可以看到只有键值对 <em>&quot;a&quot; =&gt;
   &quot;green&quot;</em> 在两个数组中都存在从而被返回。值
   <em>&quot;red&quot;</em> 没有被返回是因为在
   <var class="varname"><var class="varname">$array1</var></var> 中它的键名是 <em>0</em>
   而在 <var class="varname"><var class="varname">$array2</var></var> 中 <em>&quot;red&quot;</em>
   的键名是 <em>1</em>，键 <em>&quot;b&quot;</em> 没有返回的原因是它的值和其他数组不同。
  </p>
  <p class="simpara">
    键值对 <em>key =&gt; value</em>
   中的两个值仅在 <em>(string) $elem1 === (string)
   $elem2 </em> 时被认为相等。也就是说使用了严格检查，字符串的表达必须相同。
   
  </p>
 </div>


  <div class="refsect1 seealso" id="refsect1-function.array-intersect-assoc-seealso">
  <h3 class="title">参见</h3>
  <ul class="simplelist">
   <li class="member"><span class="function"><a href="function.array-intersect.html" class="function" rel="rdfs-seeAlso">array_intersect()</a> - 计算数组的交集</span></li>
   <li class="member"><span class="function"><a href="function.array-uintersect-assoc.html" class="function" rel="rdfs-seeAlso">array_uintersect_assoc()</a> - 带索引检查计算数组的交集，用回调函数比较数据</span></li>
   <li class="member"><span class="function"><a href="function.array-intersect-uassoc.html" class="function" rel="rdfs-seeAlso">array_intersect_uassoc()</a> - 带索引检查计算数组的交集，用回调函数比较索引</span></li>
   <li class="member"><span class="function"><a href="function.array-uintersect-uassoc.html" class="function" rel="rdfs-seeAlso">array_uintersect_uassoc()</a> - 带索引检查计算数组的交集，用回调函数比较数据和索引</span></li>
   <li class="member"><span class="function"><a href="function.array-diff.html" class="function" rel="rdfs-seeAlso">array_diff()</a> - 计算数组的差集</span></li>
   <li class="member"><span class="function"><a href="function.array-diff-assoc.html" class="function" rel="rdfs-seeAlso">array_diff_assoc()</a> - 带索引检查计算数组的差集</span></li>
  </ul>
 </div>

 
</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.array-flip.html">array_flip</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.array-intersect-key.html">array_intersect_key</a></div>
 <div class="up"><a href="ref.array.html">数组 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
